<?php $this->jQuery()->enable()?>
<?php $this->JQuery()->javascriptCaptureStart()?>
jQuery(function() {
	$j('#container').attr('class', 'saved_ads');    
	
	/*jQuery(".remove").click
	(
		function()
		{
			var a=$j(this);
			jQuery.post
			(
				"/default/index/removehistory",
				{data:$j(this).attr("rel")},
				function(t)
				{
					location.reload();
					
				}
			);
			//location.reload();
			return false
		}
	);*/
	
	jQuery(".remove_all").click
	(
		function()
		{
			var a=$j(this);
			jQuery.post
			(
				"/default/index/removehistory2",
				{data:$j(this).attr("rel")},
				function(t)
				{
					$j('.serp').html("<h2><em><?php echo $this->t('Recently Viewed Ads');?></em></h2><p style='margin-left: 10px;'><?php echo $this->t("You don't have any Recently Viewed Ads")?></p>");
					
				}
			);
			return false
		}
	);
});

<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php

function pager($cur_page_num, $url_raw, $pages){
	$url_product = array();
	$prev = ($cur_page_num>1)? "?page=".($cur_page_num-1):'';
	$next = ($cur_page_num<$pages)? "?page=".($cur_page_num+1):'';
	
	if(strpos($url_raw, '?')===false)
	{
		$url_product['prev'] = $url_product['next'] = $url_raw;
		$url_product['prev'] .= ($cur_page_num>1)? str_replace("&","?",$prev):'';
		$url_product['next'] .= ($cur_page_num<$pages)? str_replace("&","?",$next):'';
	}else
	{
		//if(eregi('&page=[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]', $url_raw))// deprecated..lols
		if(preg_match('/page=[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]/i', $url_raw))
		{
			$url_product['prev'] = preg_replace("/\?page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", $prev, $url_raw);
			$url_product['next'] = preg_replace("/\?page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", $next, $url_raw);
		}else
		{
			$url_product['prev'] = $url_raw.$prev;
			$url_product['next'] = $url_raw.$next;
		}
	}
	//echo $prev." ".$next."<br>";
	return $url_product;
}


$get = $_GET;
$page      = !empty($_GET['page']) ? $_GET['page'] : 1;
$per_page  = 10;
//$listings = getBMK($this->bookmark, $page);
$listing_number = $this->count;
//echo "COUNT: ".$listing_number."<br/>Page: ".$page."<br/>";
?>
<?php 	
$pager_url = pager($page, $_SERVER["REQUEST_URI"], ceil($listing_number/$per_page));
$previous_url = $pager_url['prev'];
$next_url = $pager_url['next']; 
?>

<section class="serp">
    <h2><em><?php echo $this->t('Recently Viewed Ads');?></em></h2>
    
    <?php if($listing_number>0):?>
    <div class="nav top">
	    <a href="<?php echo $previous_url;?>" class="prev"><span>&lt;</span><?php echo $this->t('PREV');?></a>
	    <?php if($listing_number>0):?>
	    <!--p><?php echo (($page-1) * $per_page == 0)? '1':($page-1) * $per_page?>-<?php echo ($listing_number<10)?$listing_number:($page * $per_page)?> / <?php echo number_format($listing_number)?> Ads, Page <?php echo number_format($page)?> / <?php echo number_format(ceil($listing_number/$per_page))?>
		</p-->
		<p><?php echo $this->t('__1__-__2__ / __3__ Ads, Page __4__ / __5__', null, ((($page-1) * $per_page == 0)? '1':($page-1) * $per_page), ((($listing_number)<11)?$listing_number:($page * $per_page)), number_format($listing_number), number_format($page), number_format(ceil($listing_number/$per_page)))?>
		</p>
		<?php endif;?>
	    <a href="<?php echo $next_url;?>" class="next"><?php echo $this->t('NEXT');?><span>&gt;</span></a>
    </div>
    <?php if($listing_number>0):?>
	<div class="manage_tool">
	<a href="#" class="remove_all" rel="ALL"><?php echo $this->t('Remove All Recently Viewed Ads');?></a>
	</div>
    <ul>
    	<?php 
    	
    	foreach($this->bookmark as $bmk):
    		//echo "<pre>";var_dump($bmk);echo "</pre>";
			?>
			<li>
				<a href="<?php echo $bmk['url'];?>">
					<figure><img src="<?php echo $bmk['photo'];?>"></figure>
					<h1><?php echo $bmk['title'];?>
					<?php if(!empty($bmk['sold'])):?>
                        <?php //$tmp_cat = (array)$bmk['category_attached']; ?>
                        <span class="sold"><?php echo $bmk['sold']?></span>
                    <?php endif;?></h1>
					<dl class="price">
						<dd><?php echo $bmk['location'];?></dd>
					</dl>
					<dl class="price">
						<dd><?php echo $bmk['posted'];?></dd>
					</dl>
					<dl class="price">
						<dd><?php echo (!empty($bmk['sold']))?$bmk['sold']:$bmk['price'];?></dd>
					</dl>
					<span>&gt;</span>
				</a>
				<p class="action"><a class="remove" href="/user/viewed?<?php echo 'hid='.$bmk['id']; ?>" rel="<?php echo $bmk['id'];?>"><?php echo $this->t('Remove');?></a></p>
			</li>
    	<?php endforeach;?>
	</ul>
	<?php else:?>
	<li><br><?php echo $this->t("You don't have any Recently Viewed Ads")?><br><br></li/>
	<?php endif;?>
    <div class="nav bottom">
    <a href="<?php echo $previous_url;?>" class="prev"><span>&lt;</span><?php echo $this->t('PREV');?></a>
    <?php if($listing_number>0):?>
    <!--p><?php echo $this->t('Page');?> <?php echo $page;?> / <?php echo number_format(ceil($listing_number/$per_page))?></p-->
    <p><?php echo $this->t('Page __1__ / __2__', null, number_format($page), number_format(ceil($listing_number/$per_page)))?></p>
	<?php endif;?>
	<a href="<?php echo $next_url;?>" class="next"><?php echo $this->t('NEXT');?><span>&gt;</span></a>
    </div>
    <?php else:?>
    <p style="margin-left:10px;"><?php echo $this->t("You don't have any Recently Viewed Ads");?></p>
    <?php endif;?>
    
    </section>
    
    <?php echo $this->Partial('mobile/other.phtml', 'default'); ?>
    